﻿using System;
using System.Drawing;
using System.Windows.Forms;
using MacroHard.Applications.Crm.PrototypeWinForm.TaskItems;

namespace MacroHard.Applications.Crm.PrototypeWinForm {
    public partial class MainForm : Form {
        public MainForm() {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e) {
            LoadTasks();
        }

        private void LoadTasks() {
            EmployeeManagementTaskItem item = new EmployeeManagementTaskItem();
            _tasksPanel.Controls.Clear();
            AddItemToTaskPanel(item);
        }

        private void AddItemToTaskPanel(ITaskItem item) {
            if (item == null) {
                return;
            }
            
            Button taskBtn = new Button();
            taskBtn.AutoSize = true;
            taskBtn.BackColor = Color.DeepSkyBlue;
            taskBtn.FlatAppearance.BorderColor = Color.Orange;
            taskBtn.FlatAppearance.MouseDownBackColor = Color.NavajoWhite;
            taskBtn.FlatAppearance.MouseOverBackColor = Color.PapayaWhip;
            taskBtn.FlatStyle = FlatStyle.Flat;
            taskBtn.Font = new Font("Microsoft Sans Serif", 11F, FontStyle.Bold, GraphicsUnit.Point, ((134)));
            taskBtn.Image = item.Image;
            taskBtn.ImageAlign = ContentAlignment.MiddleLeft;
            taskBtn.Size = new Size(291, 40);
            taskBtn.TabIndex = 0;
            taskBtn.Text = item.Text;
            taskBtn.TextAlign = ContentAlignment.MiddleLeft;
            taskBtn.TextImageRelation = TextImageRelation.ImageBeforeText;
            taskBtn.UseVisualStyleBackColor = false;
            taskBtn.Click += delegate {
                                 _taskDescriptionPanel.Controls.Clear();
                                 if (item.DescriptionUserControl != null) {
                                     _taskDescriptionPanel.Controls.Add(item.DescriptionUserControl);
                                 }
                                 item.DescriptionUserControl.Dock = DockStyle.Fill;
                                 _workingAreaPanel.Controls.Clear();
                                 if (item.WorkingArea != null) {
                                     _workingAreaPanel.Controls.Add(item.WorkingArea);
                                     item.WorkingArea.Dock = DockStyle.Fill;
                                 }
                             };
            _tasksPanel.Controls.Add(taskBtn);
        }
    }
}